﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Net.Chirash.Twitter.TwitterClient;
using Net.Chirash.Twitter.TwitterDatabase;

namespace Net.Chirash.Twitter.TweetZone.WindowComponents
{
	/// <summary>
	/// UserBox.xaml の相互作用ロジック
	/// </summary>
	public partial class UserBox : UserControl
	{
		User _user;
		public User User
		{
			get
			{
				return _user;
			}
			set
			{
				_user = value;
				this.MainGrid.DataContext = value;
				
				//カスタム表示形式はここで定義
				ScreenNameLabel.Content = value.ScreenName + " / " + value.Name;
				if (value.IsFollowing)
					this.FollowButton.Content = "Unfollow";
			}
		}

		public UserBox(User user)
		{
			InitializeComponent();
			User = user;
		}

		private void ShowDetailButton_Click(object sender, RoutedEventArgs e)
		{
			(new UserProfileWindow(this.User)).ShowDialog();
		}

		private void FollowButton_Click(object sender, RoutedEventArgs e)
		{
			var tc = new TwitterCommand(new TwitterConnection());
			if (this.User.IsFollowing)
			{
				//Unfollow
				tc.DestroyFriendShip(this.User);
				FollowButton.Content = "Follow";
			}
			else
			{
				//Follow
				tc.CreateFriendShip(this.User, true);
				FollowButton.Content = "Unfollow";
			}
		}
	}
}
